//
//  CYWithdrawRecordCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/22.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYWithdrawRecordCell.h"



@implementation CYWithdrawRecordCellObject

@end



@interface CYWithdrawRecordCell ()

@property(nonatomic, strong)UILabel *currentStateLabel;
@property(nonatomic, strong)UILabel *currentStateDateLabel;
@property(nonatomic, strong)UILabel *amountLabel;
@property(nonatomic, strong)UIImageView *arrowImageView;
@property(nonatomic, strong)UIView *progressView;
@property(nonatomic, strong)UILabel *applyLabel;
@property(nonatomic, strong)UILabel *applyDateLabel;
@property(nonatomic, strong)UILabel *inReviewLabel;
@property(nonatomic, strong)UILabel *inReviewDateLabel;
@property(nonatomic, strong)UILabel *resultLabel;
@property(nonatomic, strong)UILabel *resultDateLabel;
@property(nonatomic, strong)UIImageView *applyDot;
@property(nonatomic, strong)UIImageView *inReviewDot;
@property(nonatomic, strong)UIImageView *resultDot;
@property(nonatomic, strong)UIView *applyLine;
@property(nonatomic, strong)UIView *inReviewLine;
@property(nonatomic, strong)UIView *bottomLine;

@end


@implementation CYWithdrawRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.currentStateLabel = [[UILabel alloc] init];
        self.currentStateLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.currentStateLabel];
        
        self.currentStateDateLabel = [[UILabel alloc] init];
        self.currentStateDateLabel.font = [UIFont systemFontOfSize:12];
        self.currentStateDateLabel.textColor = HEXCOLOR(@"444444");
        [self.contentView addSubview:self.currentStateDateLabel];
        
        self.amountLabel = [[UILabel alloc] init];
        self.amountLabel.font = [UIFont systemFontOfSize:18];
        self.amountLabel.textColor = HEXCOLOR(@"444444");
        [self.contentView addSubview:self.amountLabel];
        
        self.arrowImageView = [[UIImageView alloc] initWithImage:CYImage(@"withdraw_record_cell_arrow")];
        [self.contentView addSubview:self.arrowImageView];
        
        self.progressView = [[UIView alloc] init];
        self.progressView.backgroundColor = HEXCOLOR(@"FAFDFF");
        [self.contentView addSubview:self.progressView];
        {
            self.applyLabel = [[UILabel alloc] init];
            self.applyLabel.textColor = HEXCOLOR(@"444444");
            self.applyLabel.font = [UIFont systemFontOfSize:12];
            self.applyLabel.text = @"申请提现";
            [self.applyLabel sizeToFit];
            [self.progressView addSubview:self.applyLabel];
            
            self.applyDateLabel = [[UILabel alloc] init];
            self.applyDateLabel.textColor = HEXCOLOR(@"999999");
            self.applyDateLabel.font = [UIFont systemFontOfSize:12];
            [self.progressView addSubview:self.applyDateLabel];
            
            self.inReviewLabel = [[UILabel alloc] init];
            self.inReviewLabel.textColor = HEXCOLOR(@"444444");
            self.inReviewLabel.font = [UIFont systemFontOfSize:12];
            [self.progressView addSubview:self.inReviewLabel];
            
            self.inReviewDateLabel = [[UILabel alloc] init];
            self.inReviewDateLabel.textColor = HEXCOLOR(@"999999");
            self.inReviewDateLabel.font = [UIFont systemFontOfSize:12];
            [self.progressView addSubview:self.inReviewDateLabel];
            
            self.resultLabel = [[UILabel alloc] init];
            self.resultLabel.textColor = HEXCOLOR(@"444444");
            self.resultLabel.font = [UIFont systemFontOfSize:12];
            self.resultLabel.text = @"提现成功";
            [self.resultLabel sizeToFit];
            [self.progressView addSubview:self.resultLabel];
            
            self.resultDateLabel = [[UILabel alloc] init];
            self.resultDateLabel.textColor = HEXCOLOR(@"999999");
            self.resultDateLabel.font = [UIFont systemFontOfSize:12];
            [self.progressView addSubview:self.resultDateLabel];
            
            self.applyDot = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 11, 11)];
            self.applyDot.image = CYImage(@"public_progress_dot_e");
            [self.progressView addSubview:self.applyDot];
            
            self.inReviewDot = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 11, 11)];
            self.inReviewDot.image = CYImage(@"public_progress_dot_e");
            [self.progressView addSubview:self.inReviewDot];
            
            self.resultDot = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 11, 11)];
            [self.progressView addSubview:self.resultDot];
            
            self.applyLine = [[UIView alloc] init];
            self.applyLine.backgroundColor = HEXCOLOR(@"D8E8FA");
            [self.progressView addSubview:self.applyLine];
            
            self.inReviewLine = [[UIView alloc] init];
            [self.progressView addSubview:self.inReviewLine];
        }
        
        self.bottomLine = [UIView cy_lineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(CYWithdrawRecordCellObject *)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return object.expanding ? 165 : 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYWithdrawRecordCellObject *)object
{
    self.amountLabel.text = SAFE_NUMBER(object.model.value).amountString;
    self.applyDateLabel.text = [SAFE_NUMBER(object.model.process.applyTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd"];
    
    if(SAFE_NUMBER(object.model.process.sucTime).integerValue > 0)
    {
        self.currentStateLabel.text = @"提现成功";
        self.currentStateLabel.textColor = HEXCOLOR(@"444444");
        self.currentStateDateLabel.text = [SAFE_NUMBER(object.model.process.sucTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd HH:mm"];
        
        self.inReviewLine.backgroundColor = HEXCOLOR(@"D8E8FA");
        self.inReviewLabel.text = @"第三方支付处理完成";
        self.inReviewDateLabel.text = [SAFE_NUMBER(object.model.process.transTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd"];
        
        self.resultDot.image = CYImage(@"public_progress_dot_e");
        self.resultLabel.hidden = NO;
        self.resultDateLabel.hidden = NO;
        self.resultDateLabel.text = [SAFE_NUMBER(object.model.process.sucTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd"];
    }
    else if(SAFE_NUMBER(object.model.process.transTime).integerValue > 0)
    {
        self.currentStateLabel.text = @"支付处理中";
        self.currentStateLabel.textColor = APP_DEFAULT_COLOR_BLUE;
        self.currentStateDateLabel.text = [SAFE_NUMBER(object.model.process.transTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd HH:mm"];
        
        self.inReviewLine.backgroundColor = HEXCOLOR(@"ECECEC");
        self.inReviewLabel.text = @"第三方支付处理中";
        self.inReviewDateLabel.text = [SAFE_NUMBER(object.model.process.transTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd"];
        
        self.resultDot.image = CYImage(@"public_progress_dot_d");
        self.resultLabel.hidden = YES;
        self.resultDateLabel.hidden = YES;
    }
    else if(SAFE_NUMBER(object.model.process.applyTime).integerValue > 0)
    {
        self.currentStateLabel.text = @"等待第三方支付处理";
        self.currentStateLabel.textColor = APP_DEFAULT_COLOR_BLUE;
        self.currentStateDateLabel.text = [SAFE_NUMBER(object.model.process.applyTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd HH:mm"];
        
        self.inReviewLine.backgroundColor = HEXCOLOR(@"ECECEC");
        self.inReviewLabel.text = @"等待第三方支付处理";
        self.inReviewDateLabel.text = [SAFE_NUMBER(object.model.process.applyTime).cy_date cy_stringWithFormat:@"yyyy-MM-dd"];
        
        self.resultDot.image = CYImage(@"public_progress_dot_d");
        self.resultLabel.hidden = YES;
        self.resultDateLabel.hidden = YES;
    }
    
    self.arrowImageView.transform = object.expanding ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformIdentity;

    self.progressView.hidden = object.expanding == NO;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.currentStateLabel sizeToFit];
    self.currentStateLabel.left = 20;
    self.currentStateLabel.centerY = 22;
    
    [self.currentStateDateLabel sizeToFit];
    self.currentStateDateLabel.left = 20;
    self.currentStateDateLabel.centerY = 44;
    
    [self.amountLabel sizeToFit];
    self.amountLabel.centerY = 33;
    self.amountLabel.right = self.contentView.width - 48;
    
    self.arrowImageView.centerY = self.amountLabel.centerY;
    self.arrowImageView.right = self.contentView.width - 20;
    
    self.progressView.width = self.contentView.width - 40;
    self.progressView.height = 85;
    self.progressView.centerX = self.contentView.width / 2;
    self.progressView.top = 65;
    {
        self.applyDot.left = 40;
        self.applyDot.centerY = self.progressView.height / 2;
        
        self.inReviewDot.centerX = self.progressView.width / 2;
        self.inReviewDot.centerY = self.progressView.height / 2;
        
        self.resultDot.right = self.progressView.width - 40;
        self.resultDot.centerY = self.progressView.height / 2;
        
        self.applyLine.width = self.inReviewDot.left - self.applyDot.right - 10;
        self.applyLine.height = 1 / SCREEN_SCALE;
        self.applyLine.centerY = self.applyDot.centerY;
        self.applyLine.left = self.applyDot.right + 5;
        
        self.inReviewLine.frame = self.applyLine.frame;
        self.inReviewLine.left = self.inReviewDot.right + 5;
        
        self.applyLabel.centerX = self.applyDot.centerX;
        self.applyLabel.centerY = self.applyDot.top - 11;
        
        [self.applyDateLabel sizeToFit];
        self.applyDateLabel.centerX = self.applyDot.centerX;
        self.applyDateLabel.centerY = self.applyDot.bottom + 11;
        
        [self.inReviewLabel sizeToFit];
        self.inReviewLabel.centerX = self.inReviewDot.centerX;
        self.inReviewLabel.centerY = self.inReviewDot.top - 11;
        
        [self.inReviewDateLabel sizeToFit];
        self.inReviewDateLabel.centerX = self.inReviewDot.centerX;
        self.inReviewDateLabel.centerY = self.inReviewDot.bottom + 11;
        
        [self.resultLabel sizeToFit];
        self.resultLabel.centerX = self.resultDot.centerX;
        self.resultLabel.centerY = self.resultDot.top - 11;
        
        [self.resultDateLabel sizeToFit];
        self.resultDateLabel.centerX = self.resultDot.centerX;
        self.resultDateLabel.centerY = self.resultDot.bottom + 11;
    }
    
    self.bottomLine.width = self.contentView.width - 20;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.left = 20;
    self.bottomLine.bottom = self.contentView.height;
}

@end
